package week7.jdbc;

import java.sql.*;

public class JDBCFactory implements ConnectionFactory {
    private static String driver = "com.mysql.jdbc.Driver";
    private static String url = "jdbc:mysql://localhost:3306/shopping?rewriteBatchedStatements=true";
    private static String user = "root";
    private static String password = "tiger";

    //注册驱动
    static {
        try {
            Class.forName(driver);
        } catch (Exception e) {
            //抛去运行时期异常
            throw new RuntimeException(e);
        }
    }

    @Override
    public Connection getConnection() {
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(url, user, password);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return conn;
    }
}
